package com.yunxi.controller.sys;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.bizToBaseData.pojo.DictVO;
import com.yunxi.sys.service.DictDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-08
 */
@RestController
@RequestMapping("/admin/dict")
@Api(tags = "sys:dict", description = "字典表接口")
public class DictController {

    @Autowired
    DictDubboService dictDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(DictVO dictVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(dictDubboService.findPageByVO(dictVO, pageNum, pageSize));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(DictVO dictVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(dictDubboService.loadCas(dictVO.getDictId()));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody DictVO dict, @CurrentUser LoginInfo loginInfo) throws Exception {
        dictDubboService.saveBatch(dict);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody DictVO dict) throws Exception {
        dictDubboService.removeById(dict.getDictId());
        return ResponseUtil.ok("success");
    }

    @PostMapping("/delType")
    @ApiOperation(value = "删除字典")
    public ApiResult del(@RequestBody List<DictVO> dictList) throws Exception {
        dictDubboService.delCas(dictList);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/listByType")
    @ApiOperation(value = "查询指定类型列表")
    public Object listByType(String type) {

        return ResponseUtil.ok(dictDubboService.listByType(type));
    }

    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有字典")
    public ApiResult listAll() {
        return ResponseUtil.ok(dictDubboService.listAll());
    }

    @GetMapping("/listBySat")
    @ApiOperation(value = "查询销售助手字典")
    public ApiResult listBySat() {
        return ResponseUtil.ok(dictDubboService.listBySat());
    }
}
